using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using YTS.Tools;
using Test.ConsoleProgram.Base;

namespace Test.ConsoleProgram.Base.Work
{
    /// <summary>
    /// 工作逻辑: 位枚举
    /// </summary>
    public class Test_BitEnum : CaseModel
    {
        public Test_BitEnum()
        {
            this.NameSign = "工作逻辑: 计算产品操作数量";
            this.ExeEvent = () =>
            {
                // Print(Type.ALL);
                // Print(Type.B2 | Type.B21);
                // Print(Type.A | Type.ALL | Type.B1);
                // return true;

                return
                    (int)(Type.ALL) == 1 &&
                    (int)(Type.B2 | Type.B21) == 24 &&
                    (int)(Type.A | Type.ALL | Type.B1) == 35;
            };
        }

        [Flags]
        public enum Type
        {
            ALL = 1 << 0,
            B1 = 1 << 1,
            B11 = 1 << 2,
            B2 = 1 << 3,
            B21 = 1 << 4,
            A = 1 << 5,
            Customer = 1 << 6,
        }

        public void Print(Type type)
        {
            if ((type & Type.ALL) == Type.ALL)
                Console.WriteLine($"exist: {Type.ALL.ToString()} -> {(int)Type.ALL}");
            if ((type & Type.B1) == Type.B1)
                Console.WriteLine($"exist: {Type.B1.ToString()} -> {(int)Type.B1}");
            if ((type & Type.B11) == Type.B11)
                Console.WriteLine($"exist: {Type.B11.ToString()} -> {(int)Type.B11}");
            if ((type & Type.B2) == Type.B2)
                Console.WriteLine($"exist: {Type.B2.ToString()} -> {(int)Type.B2}");
            if ((type & Type.B21) == Type.B21)
                Console.WriteLine($"exist: {Type.B21.ToString()} -> {(int)Type.B21}");
            if ((type & Type.A) == Type.A)
                Console.WriteLine($"exist: {Type.A.ToString()} -> {(int)Type.A}");
            if ((type & Type.Customer) == Type.Customer)
                Console.WriteLine($"exist: {Type.Customer.ToString()} -> {(int)Type.Customer}");
            Console.WriteLine($"sum value: {(int)type}\n");
        }
    }
}
